<%--
  Created by IntelliJ IDEA.
  User: a'su's
  Date: 2020/9/22
  Time: 19:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>个人资料(经纪人)</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../../../taofang/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
    <link rel="stylesheet" href="../../../taofang/css/TenantCentre.css">
    <link rel="stylesheet" href="../../../taofang/css/home.css">

    <style>
        .outer{
            width: 200px;
            height: 200px;
            background-color: #000;
            opacity: 0.8;
            position:absolute;
        }
    </style>

</head>
<body>
<script src="../../../taofang/plugins/jquery-3.4.1.js"></script>
<script src="../../../taofang/plugins/bootstrap-3.3.7-dist/js/bootstrap.js"></script>

<%@include file="topB.jsp"%>
<div class="col-md-9 zy5" style="height: 680px">
    <p class="zy51">个人资料</p>
    <p class="zy52"></p>
    <div class="zy53">
        <img src="../../../taofang/img/zy53.png">基本账号资料
    </div><hr>
    <div class="zy54">
        头像:
        <img class="img-circle zy56" src="../../../taofang/img/h2.png">
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal1">修改</button>
        <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel1">更改头像</h4>
                    </div>
                    &nbsp&nbsp&nbsp
                    <input class="zy56" type="text" placeholder="请输入更改的手机号">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        账号:
        ${register.account}
    </div><hr>
    <div class="zy54">
        密码:
        <span id="pwdspan" class="zy56" style="display: none">${register.password}</span>
        <span class="zy56">*****</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal2">修改</button>
        <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel2">密码更改</h4>
                    </div>
                    &nbsp;修改密码:
                    <input id="pwd" class="zy56" type="password" placeholder="请输入更改的密码&nbsp;(6-8位,字母或者数字)" onblur="pwd1()" onfocus="pwd11()">
                    <span style="color: red;display: none" id="pwdspan1">密码格式不对</span>
                    <span id="pwdspan2" style="color: red;display: none">密码与原密码一样</span>
                    <br>
                    &nbsp;确认密码:
                    <input id="pwd2" class="zy56" type="password" placeholder="请再次输入更改的密码" onblur="pwd4()" onfocus="pwd44()">
                    <span style="color: red;display: none" id="pwdspan4">密码与上面密码不一致</span>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changepwd()" class="btn btn-primary">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        手机:
        <span id="phonespan" class="zy56">${agent.phone}</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal3">修改</button>
        <div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel3">手机号更改</h4>
                    </div>
                    &nbsp&nbsp&nbsp
                    <input class="zy56" id="phone" type="text" placeholder="请输入更改的手机号">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changephone()" data-dismiss="modal" class="btn btn-primary">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        姓名:
        <span id="namespan" class="zy56">${agent.name}</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal4">修改</button>
        <div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel4">姓名添加修改</h4>
                    </div>
                    &nbsp&nbsp&nbsp
                    <input class="zy56" id="name" type="text" placeholder="请输入姓名(10个字符以内)">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changename()" data-dismiss="modal" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        身份证号:
        <span id="identityspan" class="zy56">${agent.identityCardNumber}</span>
        <button id="hide" class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal5">认证</button>
        <div class="modal fade" id="myModal5" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel5">身份认证</h4>
                    </div>
                    &nbsp;&nbsp;&nbsp
                    <input class="zy56" id="identity" type="text" placeholder="请输入身份证号">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" data-dismiss="modal" onclick="insertIdentity()" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>

    <div class="zy54" id="big">
        经纪人照片:
        <img src="../../../taofang/img/zhizhao.jpg" style="width: 10%;height: 50px">
        执照:
        <img src="../../../taofang/img/zhizhao.jpg" style="width: 10%;height: 50px">
    </div><hr>


    <div class="zy54">
        <span style="float: left">性别:</span>
        <div style="padding-top: 2%">
            <select id='gender' onchange="changegender()" class="form-control zy577">
                <option <c:if test="${agent.gender==true}">selected</c:if>>男</option>
                <option <c:if test="${agent.gender==false}">selected</c:if>>女</option>
            </select>
        </div>
    </div>
</div>

<%@include file="BottomB.jsp"%>

<input type="hidden" id="registerId" value="${register.id}">





<script>


    $(function () {
        let identityspan = document.getElementById("identityspan").innerText;
        if (identityspan!=""){
            let hide = document.getElementById("hide").style.display="none";
        }
    })



    $(function(){
        let divs = document.getElementById("big");
        let imgs = divs.getElementsByTagName("img");

        let body = document.getElementsByTagName("body")[0];

        for (let i=0;i<imgs.length;i++) {
            imgs[i].onmouseover=function(){

                //1. 创建一个div
                let div = document.createElement("div");
                div.id="imgDiv";
                div.className="outer";

                //创建一个img标签
                let img = document.createElement("img");
                img.src=this.src;
                img.style.width="200px";
                img.style.height="200px";

                div.style.left=600+"px";
                div.style.top = 550+"px";

                div.appendChild(img);

                body.appendChild(div);
            }

            imgs[i].onmouseout=function(){
                let div = document.getElementById("imgDiv");
                body.removeChild(div);
            }
        }
    })











    function pwd1() {
        let pwd = $("#pwd").val();
        let pwdspan = $("#pwdspan").text();
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        if (pwd==pwdspan){
            pwdspan2.style.display="inline"
        }
        if (!(/^[a-zA-Z0-9]{6,8}$/).test(pwd) && pwd!=""){
            pwdspan1.style.display="inline"
        }


    }


    function pwd11() {
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        pwdspan2.style.display="none"
        pwdspan1.style.display="none"
    }


    function pwd4() {
        let pwd = $("#pwd").val();
        let pwd4 = $("#pwd2").val();
        let pwdspan4 = document.getElementById("pwdspan4")
        if (pwd!=pwd4 && pwd4!=""){
            pwdspan4.style.display="inline"
        }
        if (pwd4==""){
            pwd4.style.display="none"
        }

    }


    function pwd44() {
        let pwdspan4 = document.getElementById("pwdspan4")
        pwdspan4.style.display="none"
    }

    function changepwd() {
        let pwd = $("#pwd").val();
        let pwd4 = $("#pwd2").val();
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        // let pwdspan3 = document.getElementById("pwdspan3")
        let pwdspan4 = document.getElementById("pwdspan4")
        if(  pwdspan2.style.display=="none" &&
            pwdspan1.style.display=="none" && pwdspan4.style.display=="none" && pwd!="" && pwd4!=""){
            let registerId = $("#registerId").val();
            let datas = {"id": registerId, "password": pwd}
            $.post('/taofang/Tenant/changepwd.action', datas, function (data) {
                if (data.code == 200) {
                    alert("修改成功")
                    window.location="/taofang/login/check.action"
                }else{
                    alert("修改失败")
                }
            })
        }else{
            alert("请输入正确的修改密码")
        }
    }


    function changephone() {
        let phone = $("#phone").val();
        let span = $("#phonespan").text();
        if (phone!=""){
            if(phone==span){
                alert("修改的手机号不能和原来手机号一样")
            }else {
                if ((/^1(3[0-9]|5[0-9]|8[0-9])[0-9]{8}$/).test(phone)) {
                    let agentId = $("#agentId").val();
                    let datas = {"id": agentId, "phone": phone}
                    $.post('/taofang/Agent/changephone.action', datas, function (data) {
                        if (data.code == 200) {
                            alert("修改成功")
                            let phonespan = document.getElementById("phonespan").innerText = data.data.phone;
                        }
                    })


                } else {
                    alert("请输入正确的手机号")
                }

            }
        }else{
            alert("修改不能为空")
        }
    }







    function changename() {
        let name = $("#name").val();
        let names=$("#namespan").text();
        if (name!=""){
            if (name==names){
                alert("修改的姓名不能和原来姓名一样")
            }else {
                if (name.length<11) {
                    let agentId = $("#agentId").val();
                    let datas = {"id": agentId, "name": name}
                    $.post('/taofang/Agent/changename.action', datas, function (data) {
                        if (data.code == 200) {
                            alert("修改成功")
                            let namespan = document.getElementById("namespan").innerText = data.data.name;
                        }
                    })
                }else{
                    alert("姓名不能超过10字符")
                }
            }
        }else{
            alert("修改不能为空")
        }
    }



    function changegender() {
        let genval = $("#gender").val();
        let vals;
        if ("男"==genval){
            vals = "true";
        }else{
            vals="false";
        }

        let agentId = $("#agentId").val();
        let datas={"id":agentId,"gender":vals}
        $.post('/taofang/Agent/changegender.action',datas,function (data){
            if (data.code==200){
                alert("修改成功")
            }
        })
    }



    function insertIdentity() {
        let identity = $("#identity").val();
        let agentId = $("#agentId").val();
        let datas = {"id":agentId,"identity":identity}
        if(identity!=""){

            if(( /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/)
                .test(identity)){
                $.post('/taofang/Agent/insertIdentity.action', datas, function (data) {
                    if (data.code == 200) {
                        alert("认证成功")
                        let identityspan = document.getElementById("identityspan").innerText = data.data.identityCardNumber;
                        let hide = document.getElementById("hide").style.display = "none";
                    }
                })
            }else{
                alert("请输入正确的身份证号")
            }
        }else{
            alert("修改不能为空")
        }

    }

</script>






</body>
</html>
